﻿#include "IBLLOperator.h"
#include <QDebug>
#include <QMutexLocker>

using namespace CVV::Interface;
IBLLOperator::IBLLOperator(QObject *parent)
    : QObject(parent)
{
    m_mapInOutParam.clear();
}

bool IBLLOperator::init(const QString &engineKey, std::shared_ptr<IPluginParam> param)
{
    Q_UNUSED(param)
    Q_UNUSED(engineKey)
    qDebug()<<__FUNCTION__<<"IBLLOperator init";
    return true;
}


std::shared_ptr<IPluginParam> IBLLOperator::getBLLParam()
{
    return std::make_shared<IPluginParam>();
}

void IBLLOperator::initParam(const QMap<QString, std::shared_ptr<IPluginParam> > &mapInOutParam)
{
    QMutexLocker locker(&m_mutex);
    m_mapInOutParam = mapInOutParam;
}

QVariant IBLLOperator::getValue(const QString &strPath)
{
    QStringList lstStr = strPath.split(".");
    if (lstStr.size() == 3)
    {
        QString strKey = strPath.mid(0, strPath.lastIndexOf("."));
        std::shared_ptr<IPluginParam> pPreParam = nullptr;
        {
            QMutexLocker locker(&m_mutex);
            pPreParam = m_mapInOutParam.value(strKey);
        }

        if (pPreParam)
        {
            QString strCode = lstStr.last();
            QVariant var;
            if (pPreParam->hasDynamicProperty(strCode))
            {
                var = pPreParam->getDynamicPropertyValue(strCode);
            }
            else
            {
                var = pPreParam->property(strCode.toStdString().c_str());
            }

            return var;
        }
    }

    return QVariant();
}


IBLLOperator::~IBLLOperator()
{

}
